<!DOCTYPE html>
<html lang="cn">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="chapter" content="bi">

  <!-- For Facebook Sharing -->
  <meta property="og:url" content="http://students.brown.edu/seeing-theory/bayesian-inference/" />
  <meta property="og:type" content="article" />
  <meta property="og:title" content="统计推断：贝叶斯学派" />
  <meta property="og:description" content="贝叶斯学派的思想是用数据来更新特定假设的概率。" />
  <meta property="og:image" content="http://students.brown.edu/seeing-theory/img/share/5.png" />
  <meta property="og:image:width" content="1200" />
  <meta property="og:image:height" content="630" />

  <title>看见统计 - 统计推断：贝叶斯学派</title>
  <!-- CSS Imports -->
  <!-- Fonts -->
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link href="https://fonts.font.im/css?family=Assistant:300,400,600,700" rel="stylesheet">
  <!--Favicon-->
  <link rel="shortcut icon" type="image/png" href="../img/favicon.png" />
  <!-- General Chapter -->
  <link rel="stylesheet" type="text/css" href="../css/chapter-style.css">
  <!-- Specific Chapter -->
  <link rel="stylesheet" type="text/css" href="bayesian-inference.css">
  <!-- JavaScript Imports -->
  <!-- D3 -->
  <script src="../js/d3.min.js"></script>
  <!-- Jquery -->
  <script src="../js/jquery.min.js"></script>
  <script src="../js/jquery-ui.js"></script>
  <!-- jstat -->
  <script src="../js/jstat.min.js"></script>
  <!-- MathJax -->
  <script type="text/javascript" async
    src="https://cdnjs.loli.net/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
  <!-- Tool Tip -->
  <script src="../js/d3.tip.v0.6.3.js"></script>
  <!-- General Chapter -->
  <script src="../js/chapter.js"></script>
  <!-- Visualizations -->
  <script src="bayesian-inference.js"></script>
</head>

<body id='5'>
  <div id="share-modal"></div>
  <div class="header">
    <div class="progress-bar">
      <div class="progress-bar-color"></div>
    </div>
    <div class="header-wrapper">
      <ul class="chapter-nav">
        <li>
          <span onclick="openNav()" id="hamburger">&#9776; </span>
        </li>
        <li><a href="../cn.html" id="seeing-theory">看见统计</a></li>
        <li><a onclick='toTop()' id='display-chapter'>第五章：统计推断：贝叶斯学派</a></li>
      </ul>
    </div>
  </div>
  <div class="col-left">
    <div class="col-left-wrapper">
      <div id="section0">
        <div class="chapter-intro">
          <h4>第五章</h4>
          <h1>统计推断：贝叶斯学派</h1>
          <p>贝叶斯学派的思想是用数据来更新特定假设的概率。
          </p>
        </div>
        <div class="scroll-down"> <img src="../img/button/bottom-arrow.svg"></div>
      </div>
      <div id="section1">
        <div class="unit">
          <h3>贝叶斯公式</h3>
          <p>
            假设你最近去看了医生，并决定检查一下自己有没有得一种罕见的疾病。如果你很不幸地收到了阳性的结果，你可能最想知道的是“已知这个检查结果，我真的得了这种病的概率是多少？”（毕竟医疗检查并不是100%准确的。）有了贝叶斯公式，我们就可以准确地计算出上述事件的概率：
          </p>

          <span id="mathjax-5-1">$$P(\text{患病}|阳性) = \dfrac{P(阳性|\text{患病})P(\text{患病})}{P(阳性)}$$</span>
          <p>从上述公式我们可以看出，已知检查结果阳性患病的<em>后验</em>还依赖于概率患病的<em>先验</em>概率\( P(\text{患病})
            \)。我们可以把这个患病的先验概率理解为人群中患有这个疾病的概率。拖拽下方的柱状图来调整这个先验概率。</p>
          <div class="interactive-wrapper">
            <div id="bayes_prior"></div>
          </div>
          <p>另一方面，后验概率还依赖于检查的准确程度：一个健康的人收到阴性结果的概率是多少？一个患者收到阳性结果的概率是多少？你可以在下方确定这两者的概率。</p>
          <div id="bayes_likelihood"></div>
          <p> 最后，我们还需要知道这个检查给出阳性结果的总概率。你可以点击下方的按钮来生成一些样本，模拟检查过程。</p>
          <div class="interactive-wrapper">
            <div class="button-1" id="test_one">检查一位患者</div>
            <div class="button-1" id="test_rest">检查所有患者</div>
            <table id="marginal">
              <tr>
                <th>阴性</th>
                <th>阳性</th>
              </tr>
              <tr>
                <td id="neg"></td>
                <td id="pos"></td>
              </tr>
            </table>
          </div>
          <p>以上就是计算后验概率所需要的所有信息。下方的表格给出了利用贝叶斯公式算出的其他后验概率。</p>
          <div class="interactive-wrapper">
            <table id="posterior">
              <tr>
                <th></th>
                <th>阴性</th>
                <th>阳性</th>
              </tr>
              <tr>
                <th>健康</th>
                <td id="h_n"></td>
                <td id="h_p"></td>
              </tr>
              <tr>
                <th>患病</th>
                <td id="d_n"></td>
                <td id="d_p"></td>
              </tr>
            </table>
            <div class="button-1" id="sort">分类</div>
            <!-- <div class="button-1" id="unsort">Unsort</div> -->
            <div class="button-1" id="reset">重置</div>
          </div>
        </div>
      </div>
      <div id="section2">
        <div class="unit">
          <h3>似然函数</h3>
          <p>在统计学中， <em>似然函数</em> 的定义是：</p><span id="mathjax-5-2">
            $$L(\theta | x) = P(x | \theta)$$</span>
          <p>似然函数的概念在频率学派和贝叶斯学派中都有重要的作用。</p>
          <div class="interactive-wrapper">
            <select id="dist" class="st-dropdown">
              <option disabled selected> -- 选择概率分布 -- </option>
              <option value="uniform">均匀分布 Uniform (0,&theta;)</option>
              <option value="normal">正态分布 Normal (&theta;, 1)</option>
              <option value="exponential">指数分布 Exponential (&theta;)</option>
              <option value="bernoulli">伯努利分布 Bernoulli (&theta;)</option>
              <option value="binomialDiscrete">二项分布 Binomial (3, &theta;)</option>
              <option value="poisson">泊松分布 Poisson (&theta;)</option>
              <option value="">清除</option>
            </select>
          </div>
          <p> 选择样本大小\(n\)然后生成样本。</p>
          <div class="interactive-wrapper">
            <div class="st-slider">
              <p> \(n\) = <span id="sample_size-value">1</span></p>
              <input type="range" id="sample_size" min="1" max="20" step="1" value="1" class="blueSlider">
            </div>
            <div id="sample" class="button-1">生成样本</div>
          </div>
          <p>拖动<span class="purple-color">紫色</span>滑块（改变\(\theta\)的值）并观察似然函数。</p>
        </div>
      </div>
      <div id="section3">
        <div class="unit">
          <h3>从先验概率到后验概率</h3>
          <p> 贝叶斯统计的核心思想是利用观察到的数据来更新先验信息。考虑一枚不均匀的硬币，抛出正面的概率为\(p\)。下面的紫色滑块可以调整\(p\)的大小（假设在现实中我们并不知道\(p\)）。</p>
          <div class="interactive-wrapper">
            <div class="st-slider">
              <p> \(p\) = <span id="p-value">0.5</span></p>
              <input type="range" id="p" min="0" max="1" step="0.01" value="0.5" class="greenSlider">
            </div>
          </div>
          <p>粉色的滑块可以调整\(p\)的先验分布。这里我们假定\(p\)的先验分布是Beta(\(\alpha,\beta\))，在图中粉色曲线代表了先验概率的密度分布函数。</p>
          <div class="st-slider">
            <p>\(\alpha\) = <span id="alpha-value">1</span></p>
            <input type="range" id="alpha" min="0.01" max="5" step="0.01" value="1" class="blueSlider">
          </div>
          <div class="st-slider">
            <p> \(\beta\) = <span id="beta-value">1</span></p>
            <input type="range" id="beta" min="0.01" max="5" step="0.01" value="1" class="blueSlider">
          </div>
          <p>当我们重复抛硬币时，我们不断更新关于\(p\)的后验分布。这个后验分布就是我们对\(p\)的最好估计，同时这也是我们相对我们下一次抛硬币结果的先验信息。</p>
          <div class="interactive-wrapper">
            <div id="coinWrapper">
              <div id="coin"></div>
              <div id="coinButtons">
                <div class="button-1" id="flip_1">抛硬币</div>
                <div class="button-1" id="flip_10">抛10次硬币</div>
              </div>
              </br></br>
            </div>
          </div>

          <div id="coinWrapper2">
            <div class="coin-img">
              <img src="./img/tail.png" alt="tail">
            </div>
            <div class="coin-text">
              = <span id="tail"></span>
            </div>

            <div class="coin-img">
              <img src="./img/head.png" alt="head">
            </div>
            <div class="coin-text">
              = <span id="head"></span>
            </div>
          </div>

        </div>
      </div>
    </div>
    <div class="action-buttons">
      <ul>
        <a href="../doc/bayesian-inference.pdf">
          <li><i class="fa fa-file-text-o action-icon" aria-hidden="true"></i> <span>下载英文PDF</span></li>
        </a>
        <a id="share-button" class="inline-share">

          <li><i class="fa fa-share-square-o action-icon" aria-hidden="true"></i>分享</li>
          <li>
            <div id="share" data-sites="weibo,qq,douban,wechat, facebook, twitter, google,linkedin"></div>
          </li>
          <li>
            <div id="share-modal"></div>
          </li>

        </a>
      </ul>
    </div>
    <a href="../regression-analysis/cn.html">
      <div class="chapter-footer" id="next-chapter-color">
        <div class="chapter-footer-wrapper">
          <h4>下一章</h4>
          <p id='next-chapter'>回归分析 → </p>
        </div>
      </div>
    </a>
  </div>
  <div class="col-right">
    <div class='language-setting'>
      <select class="languageSetting">
        <option selected>中文</option>
        <option data-url="index.html">English</option>
        <option data-url="es.html">Español</option>
      </select>
    </div>
    <div class="nav-section" id="section-0">
      <div class="nav-unit-wrapper" id='one'>
        <img src="../img/tiles/5-1.png">
        <span class="nav-unit-title"> 贝叶斯公式 </span>
      </div>
      <div class="nav-unit-wrapper" id='two'>
        <img src="../img/tiles/5-2.png">
        <span class="nav-unit-title"> 似然函数 </span>
      </div>
      <div class="nav-unit-wrapper" id='three'>
        <img src="../img/tiles/5-3.png">
        <span class="nav-unit-title"> 从先验概率到后验概率 </span>
      </div>
    </div>
    <div class="visualization-section" id="section-1">
      <div class="visualization-wrapper" id="bayes"></div>
    </div>
    <div class="visualization-section" id="section-2">
      <div class="visualization-wrapper" id="likelihood"></div>
    </div>
    <div class="visualization-section" id="section-3">
      <div class="visualization-wrapper" id="prior"></div>
    </div>
  </div>
  <div id="overlay">
    <div class="modal-header">
      <div class="closebtn" onclick="closeNav()">&times;</div>
      <ul>
        <li>
          <select class="languageSetting">
            <option selected>中文</option>
            <option data-url="index.html">English</option>
            <option data-url="es.html">Español</option>
          </select>
        </li>
        <li><a href="../index.html">首页</a></li>
      </ul>
    </div>
    <div class="modal-wrapper">
      <div class="modal-chapter">
        <div id="chapter-text"><span>CHAPTER</span></div>
        <ul class="modal-chapter-titles">
          <li id="bp-li">基础概率论</li>
          <li id="cp-li">进阶概率论</li>
          <li id="pd-li">概率分布</li>
          <li id="fi-li">统计推断：频率学派</li>
          <li id="bi-li" class="chapter-highlighted">统计推断：贝叶斯学派</li>
          <li id="ra-li">回归分析</li>
        </ul>
      </div>
      <div class="modal-visualization">
        <div id="bp" class="current">
          <div class="nav-unit-wrapper-s tile1">
            <img src="../img/tiles/1-1.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 随机事件 </span>
          </div>
          <div class="nav-unit-wrapper-s tile2">
            <img src="../img/tiles/1-2.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 期望 </span>
          </div>
          <div class="nav-unit-wrapper-s tile3">
            <img src="../img/tiles/1-3.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 方差 </span>
          </div>
        </div>
        <div id="cp">
          <div class="nav-unit-wrapper-s tile1">
            <img src="../img/tiles/2-1.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 集合论 </span>
          </div>
          <div class="nav-unit-wrapper-s tile2">
            <img src="../img/tiles/2-2.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 古典概型 </span>
          </div>
          <div class="nav-unit-wrapper-s tile3">
            <img src="../img/tiles/2-3.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 条件概率 </span>
          </div>
        </div>
        <div id="pd">
          <div class="nav-unit-wrapper-s tile1">
            <img src="../img/tiles/3-1.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 随机变量 </span>
          </div>
          <div class="nav-unit-wrapper-s tile2">
            <img src="../img/tiles/3-2.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 离散型和连续型随机变量 </span>
          </div>
          <div class="nav-unit-wrapper-s tile3">
            <img src="../img/tiles/3-3.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 中心极限定理 </span>
          </div>
        </div>
        <div id="fi">
          <div class="nav-unit-wrapper-s tile1">
            <img src="../img/tiles/4-1.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 点估计理论 </span>
          </div>
          <div class="nav-unit-wrapper-s tile2">
            <img src="../img/tiles/4-2.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 置信区间 </span>
          </div>
          <div class="nav-unit-wrapper-s tile3">
            <img src="../img/tiles/4-3.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> Bootstrap方法 </span>
          </div>
        </div>
        <div id="bi" class="current">
          <div class="nav-unit-wrapper-s tile1">
            <img src="../img/tiles/5-1.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 贝叶斯公式 </span>
          </div>
          <div class="nav-unit-wrapper-s tile2">
            <img src="../img/tiles/5-2.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 似然函数 </span>
          </div>
          <div class="nav-unit-wrapper-s tile3">
            <img src="../img/tiles/5-3.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 从先验概率到后验概率 </span>
          </div>
        </div>
        <div id="ra">
          <div class="nav-unit-wrapper-s tile1">
            <img src="../img/tiles/6-1.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 最小二乘法 </span>
          </div>
          <div class="nav-unit-wrapper-s tile2">
            <img src="../img/tiles/6-2.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 相关性 </span>
          </div>
          <div class="nav-unit-wrapper-s tile3">
            <img src="../img/tiles/6-3.png" class="nav-unit-tile-s">
            <span class="nav-unit-title-s"> 方差分析 </span>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- Share CSS and JavaScript -->
  <link rel="stylesheet" href="../css/share.min.css">
  <script src="../js/jquery.share.min.js"></script>
  <script>
    $('#share').share();

    $(".languageSetting").change(function() {
      var option = $(this).find('option:selected');
      window.location.href = option.data("url");
    });
  </script>
</body>

</html>
